<?php
/**
 * Fang_DAO_Cate
 * 
 * 作者:  姚刚 (yaogang@the9sense.com)
 * 创建时间: 2011-04-04 16:39:51
 * 修改记录: 
 * 
 * $Id: Cate.php 20 2011-04-17 13:00:27Z coosuu $
 */

class Fang_DAO_Cate extends DAO_Mysql {

    const STATUS_NORAML = 1;

    const STATUS_REMOVE = 9;

    private static $_table = 'fang_cates';

    /**
     * add 
     * 
     * @param  mixed $data 
     * @return void
     */
    public static function add($data) {

        if (!$data['c_created']) {
            $data['c_created'] = date('Y-m-d H:i:s');
        }

        return parent::add(self::$_table, $data);
    }

    /**
     * update 
     * 
     * @param  mixed $cid 
     * @param  mixed $data 
     * @return void
     */
    public static function update($cid, $data) {

        if (!$data['c_updated']) {
            $data['c_updated'] = date('Y-m-d H:i:s');
        }

        return parent::updateByKey(self::$_table, $data, $cid);
    }

    /**
     * remove 
     * 
     * @param  mixed $cid 
     * @return void
     */
    public static function remove($cid) {

        $data = array('c_status' => self::STATUS_REMOVE);
        return self::update($cid, $data);
    }

    /**
     * listAll 
     * 
     * @return void
     */
    public static function listAll() {

        return parent::getAll(self::$_table, 'c_status != ?', array(self::STATUS_REMOVE));
    }

    /**
     * listByParentId 
     * 
     * @param  integer $parentId 
     * @return void
     */
    public static function listByParentId($parentId = 0) {

        $conditions = 'c_parent_id = ?';
        $params = array($parentId);
        return parent::getAll(self::$_table, $conditions, $params);
    }

    /**
     * getInfo 
     * 
     * @param  mixed $cid 
     * @param  array $fields 
     * @return void
     */
    public static function getInfo($cid, $fields = array()) {

        $conditions = 'cid = ?';
        $params = array($cid);
        return parent::getRow(self::$_table, $conditions, $params);
    }
}
